﻿@{
    ViewBag.Title = "编辑地址";
    Layout = "~/Views/Shared/_layoutPersonal.cshtml";
}
@Styles.Render("~/Content/css/addAddress")

<article class="main">
    <nav class="mod_nav">
        <div class="lay_left">
            <a class="nav_back" onclick="turnBack()"><img src="/images/TurnBackNormal.png"></a>
            <span>编辑地址</span>
        </div>
    </nav>
    <div class="alert alert-warning" style="display:none" role="alert">
        <strong></strong>
    </div>
    <section class="mod_input">
        <ul>
            <li>
                <label>联系人</label><input id="userName" placeholder="姓名" type="text">
            </li>
            <li class="check">
                <a>
                    <span id="man" class="Input_check input_uncheck"></span>
                    <span>先生</span>
                </a>
                <a>
                    <span id="woman" class="Input_check input_checked"></span>
                    <span>女士</span>
                </a>
            </li>
            <li>
                <label>地址</label><input id="address" type="text" placeholder="详细收货地址">
            </li>
            <li>
                <label>手机号</label><input id="phoneNumber" type="tel" placeholder="配送人员联系您的电话">
            </li>
        </ul>
    </section>
    <section class="mod_btn">
        <a class="btn_save" onclick="saveAddress()">保存</a>
    </section>
</article>

<script>
    window.onload = function () {
        loadEditDeliveryAddr();
    }
    
    function loadEditDeliveryAddr() {
        var deliveryAddr = DeliveryAddrMgr.getEditDeliveryAddr();
        if (null != deliveryAddr) {
            $("#userName").attr("value", deliveryAddr.username);
            $("#address").attr("value", deliveryAddr.deliveryaddr);
            $("#phoneNumber").attr("value", deliveryAddr.userphone);
            if (true == Number(deliveryAddr.sex)) {
                $("#man").addClass("input_checked");
                $("#man").removeClass("input_uncheck");
                $("#woman").addClass("input_uncheck");
                $("#woman").removeClass("input_checked");
            } else {
                $("#woman").addClass("input_checked");
                $("#woman").removeClass("input_uncheck");
                $("#man").addClass("input_uncheck");
                $("#man").removeClass("input_checked");
            }
        }
    }

    function saveAddress() {
        var deliveryAddr = DeliveryAddrMgr.getEditDeliveryAddr();
        var deliveryAddrTemp = getTempSaveDeliveryAddress(deliveryAddr);
        if (null != deliveryAddrTemp) {
            DeliveryAddrMgr.saveDeliveryAddr(deliveryAddrTemp, saveDeliveryAddrCallback);
        }
    }

    function turnBack() {
        window.location.href = '@Url.Content("~/")' + 'DeliveryAddr/Index';
    }
</script>